﻿using Assets.Scripts.System;
using System;
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace Assets.Scripts.UI
{
    public class CMDPanel : BasePanel
    {
        public TextMeshProUGUI inputText;
        public Button button;
        public void SendButtonPressed()
        {
            inputText.text = string.Empty;
            AnalysisCommand(inputText.text);
            UISystem.Instance.StartCoolingCoro(CoolingType.Player, 5.0f);
        }
        public void AnalysisCommand(string command)
        {
            int mid = 0;
            command = command.Replace('\u200b', ' ').Trim();
            string[] commandList = command.Split(' ');
            switch (commandList[0])
            {
                case "health":
                    switch (commandList[1])
                    {
                        case "sub":
                            mid = Convert.ToInt32(commandList[2].Trim());
                            PlayerSystem.Instance.GetPlayerGO().GetComponent<PlayerHealthController>().Hit(mid);
                            break;
                        case "add":
                            mid = Convert.ToInt32(commandList[2].Trim());
                            PlayerSystem.Instance.GetPlayerGO().GetComponent<PlayerHealthController>().Recover(mid);
                            break;
                    }
                    break;
                case "weapon":
                    PlayerSystem.Instance.GetPlayerGO().GetComponent<PlayerWeaponController>().EquipWeapon(commandList[1]);
                    ////WeaponSystem.Instance.GetWeapon(commandList[1], GameObject.FindGameObjectWithTag("Player").transform);
                    //for (int i = 1; i < commandList.Length; i++)
                    //{
                    //    //playerWeaponController.EquipWeapon(commandList[i]);
                    //}
                    break;
                default:
                    break;
            }
        }
    }
}